package com.neuedu.javase.jdbc.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-10-12 13:40
 * 描述 :
 */
public class AccountDao extends BaseDao {


    public int update( Connection con , String sql ,Object ... params) throws SQLException {

        PreparedStatement stmt = null;
        int count = 0;
        try {
            stmt = con.prepareStatement(sql);
            System.out.println("sql = " + sql);

            //绑定变量
            int index = 0;
            for (Object param : params) {
                stmt.setObject(++index ,param );
            }
            count = stmt.executeUpdate();

        }  catch (SQLException throwables) {
            throw  throwables;
        } finally {
            if(stmt != null){
                stmt.close();
            }
        }

        return count;
    }


}
